<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增事项')" />
    <th:block th:include="include :: datetimepicker-css" />
    <!--<link th:href="@{/css/tree.css}" rel="stylesheet"/>-->
    <style>
    
		/* #company{
			display: none;
			padding-top: 15px;
		} */
		
		#dept{
			display: none;
		}
		
        #box1 {
            margin: 0px auto;
            width: 100%;

        }
        * {
            margin: 0;
            padding: 0;
        }




        #_zeren{
            display: none;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-matter-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>事项名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required/>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">事项分类：</label>
                <div class="col-sm-8">
                <div class="input-group">
            		<input id="typeId" name="typeId" type="hidden" />
                    <input name="typeName" class="form-control"  type="text" onclick="selectTypeTree()" id="typeName" placeholder="请选择事项类型 " required>
				        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">责任单位类型：</label>
                <div class="col-sm-8">
					<label class="radio-box" for="com" > <input type="radio" id="com" name="orgStatus" value="0" checked="checked" /> 企业 </label>
					<label class="radio-box" for="dep" > <input type="radio" id="dep" name="orgStatus" value="1" /> 部门 </label>
				</div>
            </div>

            <div class="form-group" id='dept'>
                <label class="col-sm-3 control-label">责任部门：</label>
                <div class="col-sm-8">
                    <div class="input-group">
            			<input type="hidden" id="deptTreeId"/>
                        <input onclick="selectDeptTree()" id="deptName" type="text" placeholder="请选择责任部门" class="form-control" >
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group" id="_zeren">
                <label class="col-sm-3 control-label">责任人 ：</label>
                <div class="col-sm-8">
                    <div class="input-group">
            			<input name="approveUser" type="hidden" id="treeId"/>
                        <input name="approveUsername" onclick="selectUserTree()" id="treeName" type="text" placeholder="请选择责任人" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" class="form-control" type="text">
                </div>
            </div>
           
            <div class="form-group">    
                <label class="col-sm-3 control-label">红灯预警天数：</label>
                <div class="col-sm-8">
                    <input name="redLightDays" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">黄灯预警天数：</label>
                <div class="col-sm-8">
                    <input name="yelLightDays" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">预计完成时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="expectedDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">简介：</label>
                <div class="col-sm-8">
                    <textarea name="matterContent" id="matterContent" class="form-control" required></textarea>
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:src="@{/js/comboTreePlugin.js}"></script>

    <script type="text/javascript">
        var prefix = ctx + "linkong/matter"
        $("#form-matter-add").validate({
            focusCleanup: true
        });
        
        /*新增-选择事项分类树*/
        function selectTypeTree() {
        	var id = $("#typeId").val();
        	var typeTreeId = id > 0 ? id : 1;
        	var url = prefix + "/selectTypeTree/" + typeTreeId;
			var options = {
				title: '事项分类选择',
				width: "380",
				url: url,
				callBack: doTypeSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doTypeSubmit(index, layero){
			var body = layer.getChildFrame('body', index);
   			$("#typeId").val(body.find('#typeId').val());
   			$("#typeName").val(body.find('#typeName').val());
   			layer.close(index);
		}
		
        /*新增-选择责任部门树*/
        function selectDeptTree() {
        	var id = $("#deptTreeId").val();
        	var deptId = $.common.isEmpty(id) ? "100" : $("#deptTreeId").val();
        	var url = prefix + "/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doDeptSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doDeptSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
    			$("#deptTreeId").val(body.find('#deptTreeId').val());
    			$("#deptName").val(body.find('#deptName').val());
    			layer.close(index);
			}
		}
 
        /*新增-选择领导人树*/
        function selectUserTree() {
            var treeId = $("#treeId").val();
            var deptUserId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url =prefix + "/selectDeptUserTree/" + deptUserId;
            var options = {
                title: '选择责任人',
                width: "380",
                url: url,
                callBack: doUserSubmit
            };
            $.modal.openOptions(options);
        }

        function doUserSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;

            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
 
        function submitHandler() {
            if ($.validate.form()) {
	        	add();
            }
        }
        
        function add() {
			var orgStatus = $('input:radio:checked').val();
			var name = $("input[name='name']").val();
			var typeId = $("input[name='typeId']").val();
			var approveUser = $("input[name='approveUser']").val();
			var approveUsername = $("input[name='approveUsername']").val();
			var sort = $("input[name='sort']").val();
			var redLightDays = $("input[name='redLightDays']").val();
			var yelLightDays = $("input[name='yelLightDays']").val();
			var expectedDate = $("input[name='expectedDate']").val();
			// var matterContent = $('#matterContent').val();
			// alert(matterContent);
			var mainOrg = "";
			var mainOrgname = "";
		     if (orgStatus == 1){
				mainOrg = $("input[id='deptTreeId']").val();
				mainOrgname = $("input[id='deptName']").val();
			}
			$.ajax({
				cache : true,
				type : "POST",
				url : prefix + "/add",
				data : {
					"name": name,
					"typeId": typeId,
					"approveUser": approveUser,
					"approveUsername": approveUsername,
					"orgStatus": orgStatus,
					"mainOrg": mainOrg,
					"mainOrgname": mainOrgname,
					"sort": sort,
					"redLightDays": redLightDays,
					"yelLightDays": yelLightDays,
					"expectedDate": expectedDate
					// ,"matterContent": matterContent
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}

        $("input[name='expectedDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });




        $(function(){
            $('input').on('ifChecked', function(event){
                var menuType = $(event.target).val();
                if(menuType == '1'){
                    $('#dept').show();
                    $('#_zeren').show();
                }else{
                    $('#dept').hide();
                    $('#_zeren').hide();
                }
            })
        })

    </script>
</body>
</html>